package com.androidwwf.jwr;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class GameResult extends Activity{
	
	private PlayerStatistics playerc;
	
	private TextView result, resultLevelUp;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gameresult);
		init();
	}
	
	private void init()
	{
		playerc = new PlayerStatistics(this);
		result = (TextView) findViewById(R.id.tvResult);
		resultLevelUp = (TextView) findViewById(R.id.tvResultLevelUp);
		
		int points = getIntent().getIntExtra("points", 0);
		String game = getIntent().getStringExtra("typegame");
		
		
		if(game.equals("quiz"))
		{
			playerc.updatePlayerPoints(points, "quiz");
			result.setText("Totalpoints earned from the quiz: " + points);
		}
		else if(game.equals("picture"))
		{
			playerc.updatePlayerPoints(points, "picture");
			result.setText("Totalpoints earned from the compare picture game: " + points);
		}	
		
		if(playerc.checkLevelUp())
		{
			String[] lv = playerc.getPrevAndCurLevelName();
			resultLevelUp.setText("You are promoted from: "+ lv[0] + " to: "  + lv[1] + " and unlocked a new achievement!");
		}
		else
		{
			String lv1 = playerc.getPlayerLevel();
			resultLevelUp.setText("You are not promoted. Play more games to unlock achievements. Your current level is: " + lv1);
		}
	}
}
